<?php
// 页面公共部分
class AdminAction extends Action {
	public function __construct() {
		if ($_SESSION['is_admin'] != 1) {
			//			$this -> error('未授权访问！', U('Index/login'), 1);
			//			exit ;
		}
	}

	public function logout() {
		$_SESSION = NULL;
		$this -> redirect('Index/admin_login');
	}

	//公共左侧菜单
	public function leftmenu() {
		$this -> display();
	}

	//公共菜单动画
	public function menu_action() {
		$this -> display();
	}

	//公共<head>
	public function head() {
		$m = M('config') -> select();
		foreach($m as $arr){
			if($arr['config_name']=='key'){
				$key=$arr['config_value'];
			}
			if($arr['config_name']=='description'){
				$description=$arr['config_value'];
			}
			if($arr['config_name']=='title'){
				$title=$arr['config_value'];
			}
		}
		$this -> assign('key', $key);
		$this -> assign('description', $description);
		$this -> assign('title', $title);
		$this -> display();
	}

	//公共top部分
	public function top() {
		$this -> display();
	}

	public function index() {
		$this -> display();
	}

	/************用户有关操作↓*************/
	//	用户列表
	public function user_list() {
		$page=isset($_GET['page'])?$_GET['page']:1;
//		$limit=isset($_GET['limit'])?$_GET['limit']:15;
		$limit=15;
		if(isset($_GET['usergroup'])){
			$where['usergroup']=$_GET['usergroup'];
		}
		$m=M('users')->page($page)->limit($limit)->where($where)->select();
		$m_count=M('users')->where($where)->select();
		$this->assign('data',$m);
		$this->assign('nowgroup',isset($_GET['usergroup'])?$_GET['usergroup']:'all');
		$this->assign('nowpage',$page);
		$this->assign('nowlimit',$limit);
		$this -> display();
	}

	//	用户添加页面
	public function user_add() {
		$this -> display();
	}

	//	用户添加具体方法
	public function user_add_do() {
		$data['nick'] = $_POST['nick'];
		$data['username'] = $_POST['username'];
		$data['password'] = password_encode($_POST['nick']);
		$data['grade'] = $_POST['grade'];
		$data['usergroup'] = $_POST['usergroup'];
		$data['reg_ip'] = get_client_ip();
		$data['reg_time'] = time();
		if ( M('users') -> add($data)) {
			$this -> success('添加成功！', U('Admin/user_list'), 1);
		} else {
			$this -> error('添加失败！请联系管理猿。', U('Admin/user_list'), 1);
		}
	}

	//	用户删除方法
	public function user_delete() {
		$where['id'] = $_GET['user_id'];
		if ( M('users') -> where($where) -> delete()) {
			$this -> success('删除成功！', U('Admin/user_list'), 1);
		} else {
			$this -> error('删除失败！请联系管理猿。', U('Admin/user_list'), 1);
		}
	}

	//将密码重置为默认密码
	public function setPasswordToDefault() {

	}

	/************用户有关操作上*************/

	//	问题列表
	public function problem_list() {
		$this -> display();
	}

	//	问题添加
	public function problem_add() {
		$this -> display();
	}
	
	public function problem_modify(){
		$this->display();
	}

	//	竞赛列表
	public function contest_list() {
		$this -> display();
	}

	//	竞赛添加
	public function contest_add() {
		$this -> display();
	}

	//	班级列表
	public function class_list() {
		$this -> display();
	}

	//	班级添加
	public function class_add() {
		$this -> display();
	}

	public function system_config() {
		$this -> display();
	}

	public function system_info() {
		$this -> display();
	}

}
